package com.lml.jdk8.test04;

import org.junit.jupiter.api.Test;

import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author Administrator
 * @date 2020/2/26 23:02
 * Description:
 */
public class Demo {

    @Test
    void fun3() {
        //Function<Integer, String[]> func = x -> new String[x];
        Function<Integer, String[]> func = String[]::new;
        String[] apply = func.apply(3);
        System.out.println(apply.length);
    }

    @Test
    void fun2() {
        Function<Integer, Student> func = Student::new;
        Student apply = func.apply(18);
        System.out.println(apply);
    }

    @Test
    void fun1() {
        Supplier<Student> supplier1 = () -> new Student();
        Student student1 = supplier1.get();
        System.out.println(student1);

        //Student::new默认调用的是空构造器
        //因为引用的接口方法get()没有参数,那么构造器对应找的也是没有参数的
        Supplier<Student> supplier2 = Student::new;
        Student student2 = supplier2.get();
        System.out.println(student2);
    }
}
